const {characterLengthLimit,post}=require('../config/config');

module.exports=data=>{
    let {title,tags,intro,content}=data;

    if(!title)return '标题未输入';
    title=title.trim();
    if(title.length<characterLengthLimit.post.title[0] || title.length>characterLengthLimit.post.title[1])return `标题长度非法(${characterLengthLimit.post.title[0]}~${characterLengthLimit.post.title[1]})`;

    if(!tags || !tags.length)return '标签未选择';
    if(tags){
        if(!Array.isArray(tags))tags=Array(tags);
        if(!tags.every(tag=>post.tags.includes(tag)))return '标签选择非法';
    }

    if(!intro)return '简介未输入';
    intro=intro.trim();
    if(intro.length<characterLengthLimit.post.intro[0] || intro.length>characterLengthLimit.post.intro[1])return `简介内容长度非法(${characterLengthLimit.post.intro[0]}~${characterLengthLimit.post.intro[1]})`;

    if(!content)return '正文未输入';
    content=content.trim();
    if(content.length<characterLengthLimit.post.content[0] || content.length>characterLengthLimit.post.content[1])return `正文内容长度非法(${characterLengthLimit.post.content[0]}~${characterLengthLimit.post.content[1]})`;
};